<template>
    <el-row class="lives-news" id="articleList">
        <el-row>
            <el-col class="title">
                <h3>直播间设置</h3>
            </el-col>
        </el-row>

        <el-row>
            <el-form :inline="true" class="inline-form">
                <el-form-item>
                    <el-button @click="addConfig" type="primary"><i class="el-icon-edit el-icon--left"></i>修改</el-button>
                </el-form-item>
            </el-form>
        </el-row>
        <el-row>
            <el-col>
                <p>直播间名称：{{config.StudioName}}</p>
                <p>直播期间最低人数：{{config.onlineMember_min}}</p>
                <p>直播期间随机增加人数：{{config.onlineMember_rand}}</p>
                <p>非直播期间最低人数：{{config.onlineMember_min_close}}</p>
                <p>非直播期间随机增加人数：{{config.onlineMember_rand_close}}</p>
            </el-col>
        </el-row>
        <el-dialog title="直播间设置" :visible.sync="addDialog" size="tiny" @close="cancelAddCategory" class="dialog">
                <el-form :model="updates" label-width="0">
                    <el-form-item>
                        	直播间名称：<el-input v-model="updates.StudioName" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item>
                        	直播期间最低人数：<el-input v-model="updates.onlineMember_min" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item>
                        	直播期间随机增加人数：<el-input v-model="updates.onlineMember_rand" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item>
                        	非直播期间最低人数：<el-input v-model="updates.onlineMember_min_close" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item>
                        	非直播期间随机增加人数：<el-input v-model="updates.onlineMember_rand_close" auto-complete="off"></el-input>
                    </el-form-item>
                </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelAddCategory">取 消</el-button>
                <el-button type="primary" @click="set">保 存</el-button>
            </div>
        </el-dialog>
    </el-row>
</template>
<script>
import {
    getConfig,
    setConfig
} from '@/api/api'
export default {
    data() {
        return {
            addDialog: false,
            config: {
            	StudioName: '',
            	onlineMember_min: 0,
            	onlineMember_rand: 0,
            	onlineMember_min_close: 0,
            	onlineMember_rand_close: 0
            },
            updates: {
            	StudioName: '',
            	onlineMember_min: 0,
            	onlineMember_rand: 0,
            	onlineMember_min_close: 0,
            	onlineMember_rand_close: 0
            }
        }
    },
    created() {
        getConfig('StudioName,onlineMember_min,onlineMember_rand,onlineMember_min_close,onlineMember_rand_close').then(res => this.config = res)
    },
    methods: {
        set(){
            setConfig(this.updates).then(res => {
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                for (var k in this.updates) {
                	this.config[k] = this.updates[k]
                }
                this.cancelAddCategory()
            })
        },
        addConfig: function(){
            this.addDialog = true;
            for (var k in this.config) {
            	this.updates[k] = this.config[k]
            }
        },
        cancelAddCategory: function(){
            this.addDialog = false;
        }
    }
}
</script>
<style scoped lang="scss">
.lives-news {
    .title {
        font-size: 12px;
        border-bottom: 1px solid #eaeaea;
        margin-bottom: 5px;
        h3 {
            display: inline-block;
            padding: 5px 0;
            margin: 0;
            font-weight: normal;
            color: #23b7e5;
            border-bottom: 1px solid #23b7e5;
        }
    }
}
</style>